home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 34.zip
/
BS1 part 34
/
FredFish PD 314.adf
/
Zc
/
zcsrc.lzh
/
IOLib
/
strlib
/
strrpl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-09
|
508b
|
27 lines
int strrpl(string, ptrn, rpl, n)
char *string, *ptrn;
register char *rpl;
register int n;
/*
* Replace at most <n> occurances of <ptrn> in <string> with <rpl>.
* If <n> is -1, replace all. Return the number of replacments.
*/
{
register char *p, *q = string;
register int d, rlen, nn = 0;
char *strstr();
rlen = strlen(rpl);
d = rlen - strlen(ptrn);
while(n && (p = strstr(q, ptrn)))
{
++nn;
stradj(p, d);
strncpy(p, rpl, rlen);
q = p + rlen;
if(n > 0)
--n;
}
return(nn);
}